﻿using ApiGateway;
using HttpApiGateway;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper.Validate;
using RpcModel;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Service.Model;
namespace Wedonek.RpcStore.Gateway.Controller
{
    /// <summary>
    /// 服务中心管理
    /// </summary>
    internal class ControlController : ApiController
    {
        private readonly IRpcControlService _Control;

        public ControlController(IRpcControlService control)
        {
            this._Control = control;
        }
        /// <summary>
        /// 添加服务中心
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        public int Add(RpcControl add)
        {
            return this._Control.Add(add);
        }
        /// <summary>
        /// 删除服务中心
        /// </summary>
        /// <param name="id"></param>
        public void Delete([NumValidate("rpc.control.id.error", 1)] int id)
        {
            this._Control.Delete(id);
        }
        /// <summary>
        /// 获取服务中心资料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public RpcControlInfo Get([NumValidate("rpc.control.id.error", 1)] int id)
        {
            return this._Control.Get(id);
        }
        /// <summary>
        /// 服务中心查询
        /// </summary>
        /// <param name="paging"></param>
        /// <returns></returns>
        public PagingResult<RpcControlInfo> Query(BasicPage paging)
        {
            RpcControlInfo[] list = this._Control.Query(paging, out long count);
            return new PagingResult<RpcControlInfo>(count, list);
        }
        /// <summary>
        /// 修改服务中心资料
        /// </summary>
        /// <param name="set"></param>
        public void Set(IntParam<RpcControl> set)
        {
            this._Control.Set(set.Id, set.Param);
        }
    }
}
